﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'usp_UPDMS_FIT_FIGURE_MGT_Get_Search_Count')
	BEGIN
		DROP Procedure usp_UPDMS_FIT_FIGURE_MGT_Get_Search_Count
	END
GO

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
/******************************************************************************
**	Name : usp_UPDMS_FIT_FIGURE_MGT_Get_Search_Count
**	Desc : 건강지수관리의 검색결과수를 카운트한다.
**	Test Exec Query : Exec usp_UPDMS_FIT_FIGURE_MGT_Get_Search_Count
**	Called by : Fit_Dac_UPDMS_FIT_FIGURE_MGT.cs
**	Program ID : Fit1012m
**	Auth : 송시명
**	Date : 2014-05-20
*******************************************************************************
**	Change History
*******************************************************************************
**	Date:		Author:		Description:
**	--------	--------	---------------------------------------
**	
*******************************************************************************/
CREATE PROC [dbo].[usp_UPDMS_FIT_FIGURE_MGT_Get_Search_Count]
@ls_measure_dt_from nvarchar(10),
@ls_measure_dt_to nvarchar(10),
@ls_memo nvarchar(max),
@ls_file_exist varchar(1),
@ls_lang_set nvarchar(2)
AS
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SET NOCOUNT ON

--첨부파일존재여부
DECLARE @file_exist int
IF @ls_file_exist = ''
BEGIN
    SET @file_exist = 0
END
ELSE
BEGIN
    SET @file_exist = 1
END

SELECT COUNT(uffm.Seq) AS Search_Count
  FROM UPDMS_FIT_FIGURE_MGT AS uffm WITH(NOLOCK)
  JOIN UPDMS_MST_DATE AS umd WITH(NOLOCK) ON uffm.Measure_Dt = umd.Dt
 WHERE uffm.Measure_Dt >= @ls_measure_dt_from
   AND uffm.Measure_Dt <= @ls_measure_dt_to
   AND uffm.Memo LIKE '%' + @ls_memo + '%'
   AND dbo.ufn_UPDMS_Get_Exist_Attach_File(uffm.Seq, 'Fit1012m') >= @file_exist

GO